package com.leyou.page.mq;

import com.leyou.page.service.PageService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Author: wzh
 * @Date: 2019/4/11 13:48
 * @Description:
 * 本项目用到MQ的微服务包括：
 *  1）详情页微服务
 *  2）搜索微服务
 *  3）短信微服务
 */
public class PageListener {

    @Autowired
    private PageService pageService;


    /**
     *
     * @param spuId
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "page.item.insert.queue",durable = "true"),
            exchange = @Exchange(name = "ly.item.exchange",type = ExchangeTypes.TOPIC),
            key = {"item.insert","item.update"}
    ))
    public void listenCreattHtml(Long spuId){
        if (spuId == null){
            return;
        }
        //处理消息，创建静态页面
       pageService.createHtml(spuId);

    }


    /**
     *
     * @param spuId
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "page.item.delete.queue",durable = "true"),
            exchange = @Exchange(name = "ly.item.exchange",type = ExchangeTypes.TOPIC),
            key = {"item.delete"}
    ))
    public void listenDeleteHtml(Long spuId){
        if (spuId == null){
            return;
        }
        //TODO 处理消息，删除静态页面
        pageService.deleteHtml(spuId);


    }
}
